//
//  CounterView.swift
//  Counter
//
//  Created by huangguojian on 2021/11/23.
//

import SwiftUI

//计数器
struct CounterView: View {
    
    @State var count: Int
    
    var body: some View {
        VStack(alignment: .center, spacing: 8) {
            Text("计数:\(count)")
                .padding()
            HStack(spacing: 8) {
                Button(
                    action: { count += 1 },
                    label: {
                        Text("+1")
                            .bold()
                            .foregroundColor(.white)
                            .frame(maxWidth: .greatestFiniteMagnitude, maxHeight: .greatestFiniteMagnitude)
                    })
                    .background(Color.blue)
                Button("-1", action: { count -= 1 })
                    .frame(maxWidth: .greatestFiniteMagnitude, maxHeight: .greatestFiniteMagnitude)
                    .foregroundColor(.white)
                    .background(Color.red)
            }
            .frame(width: 160, height: 40)
        }
        
    }
}

struct CounterView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            CounterView(count: 0)
        }
    }
}
